package org.veridiandynamics.server.domain;

import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.util.HashSet;
import java.util.Map;

/**
 * Object is for users who are Doctors.
 * 
 * Stores information about doctor accounts.
 *
 */
public class Doctor extends User implements Serializable
{
	private Schedule mySchedule;
	
	private static final long serialVersionUID = 40L;
	
	/**
	 * Constructor for a Doctor with necessary available information pertaining to the user.
	 * Creates instance of object.
	 * 
	 * @param personalinfo Map containing personal information.
	 */
	public Doctor(Map<String, String> personalinfo) 
	{
		
		myRoles = new HashSet<Roles>();
		myRoles.add(new Roles(RoleLookup.Role.DOCTOR));
		
		setFirstName(personalinfo.get("first name"));
		setLastName(personalinfo.get("last name"));
		setMiddleName(personalinfo.get("middle name"));
		setStreetAddress(personalinfo.get("address"));
		setCity(personalinfo.get("city"));
		setState(personalinfo.get("state"));
		setZip(Integer.parseInt(personalinfo.get("zip")));
		setTelephone(personalinfo.get("telephone"));
		setCell(personalinfo.get("cell"));
		setEmail(personalinfo.get("email"));
		setUsername(personalinfo.get("username"));
		setPassword(personalinfo.get("password"));
	}
	
	/**
	 * Default constructor which initializes an empty schedule.
	 */
	public Doctor()
	{
		mySchedule = new Schedule();
		
	}
	
	/**
	 * Returns schedule.
	 * @return Schedule for this doctor.
	 */
	public Schedule getMySchedule() {
		return mySchedule;
	}
	
	/* (non-Javadoc)
	 * @see java.lang.Object#toString()
	 */
	public String toString()
	{
		return getName();
	}

	/**
	 * Sets the schedule for the doctor.
	 * 
	 * @param mySchedule The schedule to be stored.
	 */
	public void setMySchedule(Schedule mySchedule) {
		this.mySchedule = mySchedule;
	}
	
	/**
	 * Returns schedule for this instance of doctor.
	 * 
	 * @return This doctor's schedule.
	 */
	public Schedule getSchedule()
	{
		return mySchedule;
	}

	
	/**
	 * Writes Doctor object.
	 * 
	 * @param outputStream
	 * @throws IOException
	 */
	private void writeObject(ObjectOutputStream outputStream) throws IOException {
		outputStream.defaultWriteObject();
	}
	
	/**
	 * Reads particular object.
	 * 
	 * @param inputStream
	 * @throws ClassNotFoundException
	 * @throws IOException
	 */
	private void readObject(ObjectInputStream inputStream) throws ClassNotFoundException, IOException {
		inputStream.defaultReadObject();
	}
	
}
